class ListNode:
	def __init__(self, x):
	    self.val = x
	    self.next = None

class Solution:
    # @param head, a ListNode
    # @return a ListNode
    def deleteDuplicates(self, head):
    	if head is None:
    		return None
    	it = head
    	while (it is not None):
    		next = it.next
    		while (next is not None) and (it.val == next.val):
    			next = next.next
    		it.next = next
    		it = it.next
    	return head

if __name__ == '__main__':
    so = Solution()
    h = ListNode(0)
    it = h
    for i in [0,1,2,2]:
        it.next = ListNode(i)
        it = it.next
    it2 = so.deleteDuplicates(h)
    while it2 is not None:
        print it2.val
        it2 = it2.next

